var webpack = require("webpack");
var CopyWebpackPlugin = require("copy-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const WindiCSS = require('windicss-webpack-plugin');
var path = require("path");

module.exports = {
    entry: {
        client: ["@babel/polyfill", "./client/main.js"],
    },
    externals: {
        lodash: "_",
        axios: "axios",
        vue: "Vue",
        "vue-router": "VueRouter",
        vuex: "Vuex",
        "element-ui": "ElementUI"
    },
    output: {
        path: __dirname + "/dist",
        filename: "[name].js",
        chunkFilename: "[name].chunk.js"
    },
    mode: "production",
    resolve: {
        extensions: [".js", ".vue", ".json"],
        modules: [
            path.resolve('client'),
            path.resolve('node_modules')
        ],
        alias: {
            vue$: "vue/dist/vue.esm.js",
            //'~': path.join(__dirname),
            client: path.join(__dirname, "client"),
        }
    },
    module: {
        rules: [
            {
                test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"
            },
            { test: /\.vue$/, loader: "vue-loader" },
            { test: /\.css$/, use: ["vue-style-loader", "css-loader"] },
            { test: /\.(jpg|png|gif|svg)$/, use: ["url-loader?limit=10000"] },
            { test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)/, use: ["url-loader"] }
        ]
    },
    plugins: [
        //new BundleAnalyzerPlugin(),
        new WindiCSS(),
        new VueLoaderPlugin(),
        new CopyWebpackPlugin({
            patterns: [
                { from: "client/index.html", to: "index.html" },
                { from: "static", to: "static" },
                { from: "favicon.ico", to: "favicon.ico" }
            ]
        })
    ],
    performance: { hints: false }
};
